package com.playball.lottery.frm.yhzx;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.customview.ShowCustomDialog;


public class JddKeFuActivity extends BaseActivity {

	WebView webView;
	ImageView call_phone;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.jddkefu);
		final Activity activity = this;
		TextView info = (TextView) findViewById(R.id.top_title_info);
		info.setText("多多彩票客服");
		TextView back = (TextView) findViewById(R.id.top_title_back);
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		});
		call_phone = (ImageView) findViewById(R.id.call_phone_btn);
		call_phone.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// 弹出对话框
				ShowCustomDialog.Builder alertbBuilder = new ShowCustomDialog.Builder(JddKeFuActivity.this);
				alertbBuilder.setTitle("联系客服");
				alertbBuilder.setMessage("是否拨打：18674899170？");
				alertbBuilder.setNegativeButton("拨打", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						Intent phoneIntent = new Intent("android.intent.action.CALL", Uri
								.parse("tel:" + "18674899170"));
						startActivity(phoneIntent);
						dialog.dismiss();
					}
				}).setPositiveButton("取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				}).createCustomDialog().show();

			}
		});
		webView = (WebView) findViewById(R.id.jdd_kefu);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}

			public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
				Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
			}

		});

		webView.setWebChromeClient(new WebChromeClient() {
			@Override
			public void onProgressChanged(WebView view, int newProgress) {
				// TODO Auto-generated method stub
				activity.setProgress(newProgress * 1000);
			}

		});
		webView.loadUrl("http://www16.53kf.com/webCompany.php?arg=10129326&style=1&language=cn");
	}

	public void onResume() {
		super.onResume();
		
	}

	public void onPause() {
		super.onPause();
		
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (webView.canGoBack()) {
				webView.goBack();
				return true;
			} else {
				this.finish();
				return true;
			}
		} else {
			return super.onKeyDown(keyCode, event);
		}

	};

}
